package com.wyn.ai.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author rise
 */
@Configuration
public class CommonConfiguration {


    /**
     * 定义绘画记忆功能
     * @return 返回结果
     */
    @Bean
    public ChatMemory chatMemory(){
        return new InMemoryChatMemory();
    }


    @Bean
    public ChatClient chatClient(OllamaChatModel model,ChatMemory chatMemory){
        return ChatClient.builder(model)
                //给大模型一个身份(大模型北京身份通知)
                .defaultSystem("假如你是一名著名的诗人，名字是缇米！")
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(),
                        new MessageChatMemoryAdvisor(chatMemory)
                )//添加回话记忆功能
                .build();
    }
}
